package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.WorkflowApplyLineUser;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.WorkflowApplyLineUserDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2020-12-24 09:18:13
 */
public class WorkflowApplyLineUserConverts {

    private static Logger LOG = LoggerFactory.getLogger(WorkflowApplyLineUserConverts.class);

    public static List<WorkflowApplyLineUserDTO> convert(List<WorkflowApplyLineUser> workflowApplyLineUserList) {
        if (CollectionUtils.isEmpty(workflowApplyLineUserList)) {
            return Collections.EMPTY_LIST;
        }

        List<WorkflowApplyLineUserDTO> workflowApplyLineUserListResult = Lists.newArrayList();
        for (WorkflowApplyLineUser workflowApplyLineUser : workflowApplyLineUserList) {
            workflowApplyLineUserListResult.add(convert(workflowApplyLineUser));
        }
        return workflowApplyLineUserListResult;
    }

    public static WorkflowApplyLineUserDTO convert(WorkflowApplyLineUser workflowApplyLineUser) {
        try {
            return BeanUtils.copy(workflowApplyLineUser, WorkflowApplyLineUserDTO.class);
        } catch (Exception e) {
            LOG.error("WorkflowApplyLineUser到WorkflowApplyLineUserDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowApplyLineUser到WorkflowApplyLineUserDTO转换失败", e);
        }
    }

    public static WorkflowApplyLineUser convert(WorkflowApplyLineUserDTO workflowApplyLineUserDTO) {
        try {
            return BeanUtils.copy(workflowApplyLineUserDTO, WorkflowApplyLineUser.class);
        } catch (Exception e) {
            LOG.error("WorkflowApplyLineUserDTO到WorkflowApplyLineUser转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "WorkflowApplyLineUserDTO到WorkflowApplyLineUser转换失败", e);
        }
    }
}